-- window management
local hotkey = require "hs.hotkey"
local window = require "hs.window"
local hyper = {'ctrl', 'alt', 'cmd'}

-- default 0.2
window.animationDuration = 0

-- 移动当前应用的所有窗口
function move(screen)
  -- 获取当前包名
  focusWin = window.focusedWindow():application()
  localAppBundleID = focusWin:bundleID()
  -- 获取所有窗口
  local windows = window.allWindows()
  for _, win in pairs(windows) do
    local app = win:application()
    local bundleID = app:bundleID()
    if (localAppBundleID == bundleID) then
      if (screen == "right") then
        win:moveOneScreenEast()
      elseif (screen == "left") then
        win:moveOneScreenWest()
      end
    end
  end
end

-- move active window to previous monitor
hotkey.bind(hyper, "Left", function()
  -- 只移动当前窗口
  -- window.focusedWindow():moveOneScreenWest()
  move("left")
end)

-- move active window to next monitor
hotkey.bind(hyper, "Right", function()
  -- 只移动当前窗口
  -- window.launchOrFocus():moveOneScreenEast()
  move("right")
end)
